//
//  HomeViewController.m
//  community
//
//  Created by 小崔 on 2020/5/28.
//  Copyright © 2020 小崔. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeBannerTableViewCell.h"
#import "HomeVIewVM.h"
#import "TheVillageTableViewCell.h"



@interface HomeViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) UITableView * tableView;
@property(nonatomic,strong) HomeVIewVM  * homeViewVM;
@property(nonatomic,assign) BOOL   homeBannerUpdata;
@property (nonatomic,assign) int            cellRowNuber;

@end

@implementation HomeViewController


//隐藏导航栏状态
//- (BOOL)prefersStatusBarHidden {
//    return YES;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)addControllers{
    _cellRowNuber = 1;
    self.titleView.titleLab.text = @"XX委员会";
    [self.view addSubview:self.tableView];
    [self.titleView setHidden:YES];
    WEAKSELF
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view.mas_top).offset(iPhoneXStyle ? -44 : -20);
        make.left.equalTo(weakSelf.view.mas_left);
        make.right.equalTo(weakSelf.view.mas_right);
        make.bottom.equalTo(weakSelf.view.mas_bottom);

    }];
    self.homeViewVM = [HomeVIewVM new];
    RAC(self,homeBannerUpdata) = RACObserve(self.homeViewVM, homeBannerUpdata);
    [self.homeViewVM exchange];
}

- (void)setHomeBannerUpdata:(BOOL)homeBannerUpdata{
    if (homeBannerUpdata) {
        [self.tableView reloadData];
    }
}


#pragma mark- tableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        HomeBannerTableViewCell * cell = [[HomeBannerTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeBannerTableViewCell"];
           //设置网络图片数组
           cell.cycleScrollView.imageURLStringsGroup = self.homeViewVM.netImages;
           return cell;
    }else if (indexPath.row == 1){
        TheVillageTableViewCell * cell = [[TheVillageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TheVillageTableViewCell"];
        RAC(self,cellRowNuber) = RACObserve(cell, cellRowNuber);
        //设置网络图片数组
        return cell;
    }else{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
           //设置网络图片数组
        return cell;
    }
   
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 180;
    }else if (indexPath.row == 1){
        NSLog(@"%d",_cellRowNuber);
        return 20+(_cellRowNuber * 110);
    }else {
        return 1;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


-(UITableView *)tableView{
    if (!_tableView) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:HomeBannerTableViewCell.self forCellReuseIdentifier:@"HomeBannerTableViewCell"];
        [_tableView registerClass:TheVillageTableViewCell.self forCellReuseIdentifier:@"TheVillageTableViewCell"];
         [_tableView registerClass:UITableViewCell.self forCellReuseIdentifier:@"UITableViewCell"];
        _tableView.rowHeight = UITableViewAutomaticDimension;
//        _tableView.tableFooterView = [[UIView alloc]init];
        _tableView.estimatedRowHeight = 100;
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.estimatedSectionFooterHeight = 1;
        _tableView.estimatedSectionHeaderHeight = 1;
    }
    return _tableView;
}


@end
